package remote_work.core.service;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import remote_work.dto.InputObject;
import remote_work.dto.OutputObject;
import remote_work.util.DBHelper;
import remote_work.util.MyService;

/**
 * @author LiuPing
 *
 * 2018年4月15日
 */
@MyService
public class DownloadLogService {
	
	/**
	 * 记录学生下载作业日志
	 * 
	 * @param inputObject
	 * @return
	 * @throws SQLException
	 */
	public OutputObject addLog(InputObject inputObject) throws SQLException {
		OutputObject outputObject = new OutputObject();
		DBHelper db = new DBHelper();
		List<Object> params = new ArrayList<>();
		String sql = "insert into downloadlog(logid,username,filename,state,downloadtime) values (to_char(sysdate,'yyyyMMddHHmmss'),?,?,?,?)";
		params.add(inputObject.getValue("userName"));
		params.add(inputObject.getValue("fileName"));
		params.add(inputObject.getValue("state"));
		params.add(inputObject.getValue("downloadTime"));
		int doUpdate = db.doUpdate(sql, params);
		if (doUpdate < 0) {
			outputObject.setReturnCode("-1");
		}
		return outputObject;
	}
	
	/**
	 * 获取下载记录
	 * 
	 * @param inputObject
	 * @return
	 * @throws SQLException
	 */
	public OutputObject getLog(InputObject inputObject) throws SQLException {
		OutputObject outputObject = new OutputObject();
		DBHelper db = new DBHelper();
		List<Object> params = new ArrayList<>();
		String sql = "select * from downloadlog where username = ? and state = ?";
		params.add(inputObject.getValue("userName"));
		params.add(inputObject.getValue("state"));
		outputObject.setBeans(db.find(sql, params));
		return outputObject;
	}
	
}
